USE [NexusLogs]
GO
select * from
(
select 'Log_General' as [Before], count(*) as Total from Log_General
UNION ALL
select 'Log1_General', count(*) from Log1_General
UNION ALL
select 'Records_General', count(*) from Records_General
) x
go

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

/* First Update the SP to store in another table *//****** Object:  Stored Procedure dbo.WriteLog    Script Date: 10/1/2004 3:16:36 PM ******/
ALTER PROCEDURE [dbo].[WriteLog_General]
(
	@EventID int, 
	@Priority int, 
	@Severity nvarchar(32), 
	@Title nvarchar(256), 
	@Timestamp datetime,
	@MachineName nvarchar(32), 
	@AppDomainName nvarchar(512),
	@ProcessID nvarchar(256),
	@ProcessName nvarchar(512),
	@ThreadName nvarchar(512),
	@Win32ThreadId nvarchar(128),
	@Message nvarchar(1500),
	@FormattedMessage nvarchar(max),
	@LogId int OUTPUT
)
AS 
/*
AppDomainName = UserName; //512
Title = Title; //nvarchar 256
FormattedMessage = Message); //nvarchar(max)
ManagedThreadName = UserIP; //512
ProcessId = TotalSeconds.ToString(); //nvarchar 256
*/
	INSERT INTO [Log1_General] (
		[UserID], [Title], [Message], [Duration], [IP], [Server],[Date]
	)
	VALUES (
		@AppDomainName,
		@Title,		
		@FormattedMessage,
		@ProcessId,
		@ThreadName,
		@ProcessName,
		@Timestamp)

	SET @LogID = @@IDENTITY
	RETURN @LogID
go

/* Move the records into the records table */
insert into Records_General ([UserID], [Title], [Message], [Duration], [IP], [Server], [Date])
select [UserID], [Title], [Message], [Duration], [IP], [Server], [Date]
from Log_General
go

truncate table Log_General
go

/* Now update the sp to put it back in the same place */
ALTER PROCEDURE [dbo].[WriteLog_General]
(
	@EventID int, 
	@Priority int, 
	@Severity nvarchar(32), 
	@Title nvarchar(256), 
	@Timestamp datetime,
	@MachineName nvarchar(32), 
	@AppDomainName nvarchar(512),
	@ProcessID nvarchar(256),
	@ProcessName nvarchar(512),
	@ThreadName nvarchar(512),
	@Win32ThreadId nvarchar(128),
	@Message nvarchar(1500),
	@FormattedMessage nvarchar(max),
	@LogId int OUTPUT
)
AS 
/*
AppDomainName = UserName; //512
Title = Title; //nvarchar 256
FormattedMessage = Message); //nvarchar(max)
ManagedThreadName = UserIP; //512
ProcessId = TotalSeconds.ToString(); //nvarchar 256
*/
	INSERT INTO [Log1_General] (
		[UserID], [Title], [Message], [Duration], [IP], [Server],[Date]
	)
	VALUES (
		@AppDomainName,
		@Title,		
		@FormattedMessage,
		@ProcessId,
		@ThreadName,
		@ProcessName,
		@Timestamp)

	SET @LogID = @@IDENTITY
	RETURN @LogID
go


/****** Object:  Stored Procedure dbo.WriteLog    Script Date: 10/1/2004 3:16:36 PM ******/

ALTER PROCEDURE [dbo].[WriteLog_General]
(
	@EventID int, 
	@Priority int, 
	@Severity nvarchar(32), 
	@Title nvarchar(256), 
	@Timestamp datetime,
	@MachineName nvarchar(32), 
	@AppDomainName nvarchar(512),
	@ProcessID nvarchar(256),
	@ProcessName nvarchar(512),
	@ThreadName nvarchar(512),
	@Win32ThreadId nvarchar(128),
	@Message nvarchar(1500),
	@FormattedMessage nvarchar(max),
	@LogId int OUTPUT
)
AS 
/*
AppDomainName = UserName; //512
Title = Title; //nvarchar 256
FormattedMessage = Message); //nvarchar(max)
ManagedThreadName = UserIP; //512
ProcessId = TotalSeconds.ToString(); //nvarchar 256
*/
	INSERT INTO [Log_General] (
		[UserID], [Title], [Message], [Duration], [IP], [Server],[Date]
	)
	VALUES (
		@AppDomainName,
		@Title,		
		@FormattedMessage,
		@ProcessId,
		@ThreadName,
		@ProcessName,
		@Timestamp)

	SET @LogID = @@IDENTITY
	RETURN @LogID
go

/* Move the records into the records table */
insert into Records_General ([UserID], [Title], [Message], [Duration], [IP], [Server], [Date])
select [UserID], [Title], [Message], [Duration], [IP], [Server], [Date]
from Log1_General
go

truncate table Log1_General
go
select * from
(
select 'Log_General' as [After], count(*) as Total from Log_General
UNION ALL
select 'Log1_General', count(*) from Log1_General
UNION ALL
select 'Records_General', count(*) from Records_General
) x
go

select * from
(
select 'Log_Login' as [Before], count(*) as Total from Log_Login
UNION ALL
select 'Log1_Login', count(*) from Log1_Login
UNION ALL
select 'Records_Login', count(*) from Records_Login
) x
go
/****** Object:  StoredProcedure [dbo].[WriteLog_Login]    Script Date: 08/04/2008 08:59:02 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

/****** Object:  Stored Procedure dbo.WriteLog    Script Date: 10/1/2004 3:16:36 PM ******/
ALTER PROCEDURE [dbo].[WriteLog_Login]
(
	@EventID int, 
	@Priority int, 
	@Severity nvarchar(32), 
	@Title nvarchar(256), 
	@Timestamp datetime,
	@MachineName nvarchar(32), 
	@AppDomainName nvarchar(512),
	@ProcessID nvarchar(256),
	@ProcessName nvarchar(512),
	@ThreadName nvarchar(512),
	@Win32ThreadId nvarchar(128),
	@Message nvarchar(1500),
	@FormattedMessage ntext,
	@LogId int OUTPUT
)
AS 
/*
Date = @TimeStamp
Action = @Title
Result = @MachineName
UserID = @AppDomainName
IP = @ProcessName
Browser = @Message
*/
	INSERT INTO [Log1_Login] (
		[Date], [Action], [Result], [UserID], [IP], [Browser]
	)
	VALUES (
	@TimeStamp, @Title, @MachineName, @AppDomainName, @ProcessName, @Message
)

	SET @LogID = @@IDENTITY
	RETURN @LogID
go

insert into Records_Login ([Date], [Action], [Result], [UserID], [IP], [Browser])
select [Date], [Action], [Result], [UserID], [IP], [Browser]
from Log_Login
go

truncate table Log_Login
go

ALTER PROCEDURE [dbo].[WriteLog_Login]
(
	@EventID int, 
	@Priority int, 
	@Severity nvarchar(32), 
	@Title nvarchar(256), 
	@Timestamp datetime,
	@MachineName nvarchar(32), 
	@AppDomainName nvarchar(512),
	@ProcessID nvarchar(256),
	@ProcessName nvarchar(512),
	@ThreadName nvarchar(512),
	@Win32ThreadId nvarchar(128),
	@Message nvarchar(1500),
	@FormattedMessage ntext,
	@LogId int OUTPUT
)
AS 
/*
Date = @TimeStamp
Action = @Title
Result = @MachineName
UserID = @AppDomainName
IP = @ProcessName
Browser = @Message
*/
	INSERT INTO [Log_Login] (
		[Date], [Action], [Result], [UserID], [IP], [Browser]
	)
	VALUES (
	@TimeStamp, @Title, @MachineName, @AppDomainName, @ProcessName, @Message
)

	SET @LogID = @@IDENTITY
	RETURN @LogID
go

insert into Records_Login ([Date], [Action], [Result], [UserID], [IP], [Browser])
select [Date], [Action], [Result], [UserID], [IP], [Browser]
from Log1_Login
go

truncate table Log1_Login
go
select * from
(
select 'Log_Login' as [After], count(*) as Total from Log_Login
UNION ALL
select 'Log1_Login', count(*) from Log1_Login
UNION ALL
select 'Records_Login', count(*) from Records_Login
) x
go
use [master]
go
BACKUP DATABASE [Nexus] TO  DISK = N'd:\Nexus.bak' WITH NOFORMAT, INIT,  NAME = N'Nexus-Full Database Backup', SKIP, NOREWIND, NOUNLOAD,  STATS = 10
GO
BACKUP DATABASE [NexusLogs] TO  DISK = N'd:\NexusLogs.bak' WITH NOFORMAT, INIT,  NAME = N'NexusLogs-Full Database Backup', SKIP, NOREWIND, NOUNLOAD,  STATS = 10
GO

